import { defineStore ,createPinia} from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

import { getCart } from '@/service/cart';
export const useStore = defineStore('cart', {
  state: () => {
    return {
      count: 0,
      userInfo: {},
      token:''
    };
  },
  actions: {
    async updateCart() {
      const { data = [] } = await getCart();
      this.count = data.length;
    },
    updateInfo(data) {
      this.userInfo = data;
    },
    setToken(token) {
      this.token = token;
    },
  },
  persist: true,
});
